package com.dark.util;

import java.io.IOException;
import java.io.RandomAccessFile;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * ClassName: EncryptionUtil
 * Description:EncryptionUtil
 *
 * @author chengluchao
 * @date: 2023/9/22 11:18 AM
 * @since 1.4.35
 */
public class EncryptionUtil {

    public static void main(String[] args) throws Exception {
        String filePath = "/Users/chengluchao/Desktop/jingjingyunchang/RED/4091693906436_.pic_hd.jpg";
        int chunkSize = 1024 * 1024;
        List<String> list = FileUtils.sliceFile(filePath, chunkSize);
        Map<String, Integer> originalFileOrder = new HashMap<>(list.size() >> 1);
        AtomicInteger i = new AtomicInteger(1);
        list.forEach(sunpath -> originalFileOrder.put(sunpath, i.getAndIncrement()));

        System.out.println(originalFileOrder);
        generateFileHead("980", 1024);
    }

    public static void generateFileHead(String code, int size) {
        String fileName = "/Users/chengluchao/Desktop/jingjingyunchang/RED/" + code + ".txt"; // 文件名
        long fileSize = size; // 文件大小，单位为字节

        try {
            RandomAccessFile file = new RandomAccessFile(fileName, "rw");
            file.setLength(fileSize); // 设置文件大小

            Random random = new Random();
            byte[] buffer = new byte[10]; // 每次写入的字节数
            for (long i = 0; i < fileSize; i += buffer.length) {
                random.nextBytes(buffer); // 生成随机字节数组
                file.write(buffer); // 写入文件
            }

            file.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
